<?php

namespace app\api\controller;

use app\api\model\User as UserModel;
use app\common\model\store\shop\Clerk;

/**
 * 用户管理
 * Class User
 * @package app\api
 */
class User extends Controller
{
    /**
     * 用户自动登录
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\Exception
     * @throws \think\exception\DbException
     *  /user/login
     */
    public function login()
    {
        $model = new UserModel;

        $user_id = $model->login($this->request->post());

        $Clerk = Clerk::where('user_id',$user_id)
            ->where('status',1)
            ->where('is_delete',0)
            ->find();

        return $this->renderSuccess([
            'Clerk' => $Clerk,
            'user_id' => $user_id,
            'token' => $model->getToken()
        ]);
    }

    /**
     * 当前用户详情
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\exception\DbException
     */
    public function detail()
    {
        // 当前用户信息
        $userInfo = $this->getUser();
        return $this->renderSuccess(compact('userInfo'));
    }

}
